package com.fzt.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fzt.common.utils.R;
import com.fzt.system.domain.param.SysUserParam;
import com.fzt.system.domain.vo.SysUserVO;
import com.fzt.system.service.SysUserService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户管理
 * </p>
 *
 * @author 非洲铜
 * @since 2022-12-09
 */
@RestController
@RequestMapping("/sys/user")
@AllArgsConstructor
public class SysUserController {
    private final SysUserService sysUserService;

    /**
     * 用户分页查询
     *
     * @param sysUserParam 用户分页列表入参
     * @return 用户分页数据
     */
    @GetMapping("/page")
    public R<IPage<SysUserVO>> page(SysUserParam sysUserParam) {
        IPage<SysUserVO> sysUserVOIPage = sysUserService.selectPage(sysUserParam);
        return R.ok(sysUserVOIPage);
    }

    /**
     * 查询用户信息
     *
     * @param id 用户ID
     * @return 用户信息
     */
    @GetMapping("{id}")
    public R<SysUserVO> get(@PathVariable("id") Long id) {
        SysUserVO user = sysUserService.getUser(id);
        return R.ok(user);
    }

    /**
     * 保存用户
     *
     * @param sysUserVO 用户信息
     */
    @PostMapping("/save")
    public R<Void> save(@RequestBody @Validated SysUserVO sysUserVO) {
        sysUserService.saveUser(sysUserVO);
        return R.ok();
    }

    /**
     * 更新用户
     *
     * @param sysUserVO 用户信息
     */
    @PutMapping("/update")
    public R<Void> update(@RequestBody SysUserVO sysUserVO) {
        sysUserService.updateUser(sysUserVO);
        return R.ok();
    }

    @DeleteMapping("/delete")
    public R<Void> delete() {
        return R.ok();
    }


}
